package cn.fansunion.leecode.linkedlist;

import java.util.ArrayList;
import java.util.List;

/**
 * 
 * @author wen.lei@brgroup.com
 *
 * 2022-2-15
 */
public class ListNode {
    public int val;
    public ListNode next;

    ListNode() {}

    public ListNode(int val) {
        this.val = val;
    }

    public ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }

    @Override
    public String toString() {
        return "ListNode [val=" + val + ", next=" + next + "]";
    }

    //返回链表该节点和以后的所有元素，方便单元测试
    public int[] curNextValArray() {
        List<Integer> list = new ArrayList<>();
        list.add(val);
        ListNode next=this.next;
        while(next!=null) {
            list.add(next.val);
            next=next.next;
        }
        int[] valArray=new int[list.size()];
        for(int index=0;index<list.size();index++) {
            valArray[index]=list.get(index);
        }
        return valArray;
    }
    
    
}